<?php
$dbHost = $_POST['dbHost'];
$dbName = $_POST['dbName'];
$dbUsername = $_POST['dbUsername'];
$dbPassword = $_POST['dbPassword'];
$accountName = $_POST['accountName'];
$accountPassword = $_POST['accountPassword'];
$conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
if ($conn->connect_error) {
    die("conn error: " . $conn->connect_error);
}
$sqlFilePath = "inl.sql";
if (($handle = fopen($sqlFilePath, "r")) === FALSE) {
    die("无法打开 SQL 文件: " . $sqlFilePath);
}
$currentStatement = '';
while (($line = fgets($handle)) !== FALSE) {
    $line = trim($line);
    if (preg_match('/^\s*(--|#)/', $line)) {
        continue;
    }
    $currentStatement .= $line . " ";
    if (preg_match('/;\s*$/', $currentStatement)) {
        $currentStatement = trim($currentStatement, " \t\n\r\0\x0B;");
        if (!$conn->query($currentStatement)) {
            echo "执行失败: " . $conn->error . "\n";
            echo "失败的 SQL 语句: " . $currentStatement . "\n";
        }
        $currentStatement = '';
    }
}
if (!empty($currentStatement)) {
    echo "警告：文件末尾存在未完成的 SQL 语句。\n";
    echo "未完成的 SQL 语句: " . $currentStatement . "\n";
}
fclose($handle);
require '../config.php';
$linkf = '../config.php';
$ncc = "  
			<?php  
			\$db_host = '$dbHost';    
			\$db_user = '$dbUsername';    
			\$db_pass = '$dbPassword';    
			\$db_name = '$dbName';    
			?>";
file_put_contents($linkf, $ncc);
$sql = "INSERT INTO `users` (`username`, `password`) VALUES (?,?)";
$stmt = $conn->prepare($sql);
$accountPassword_md5 = md5($accountPassword);
$stmt->bind_param("ss", $accountName, $accountPassword_md5);
if ($stmt->execute()) {
    echo "success";
} else {
    echo "error";
}
$conn->close();
